package com.zx.crontask.controller;

import com.zx.crontask.timingConfig.ScheduleTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName MonitorController
 * @Description 监听
 * @Author Zx
 * @Date 2022年09月22日 10:52
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("listening")
public class TestController {

    @Resource
    private ScheduleTask scheduleTask;

    /**
     * 动态获取cron表达式，执行多线程定时任务
     *
     * @param cron 获取表达式
     * @return 返回成功
     */
    @RequestMapping("/updateCron")
    public String updateCron(@RequestParam String cron) {
        log.info("new cron :{}", cron);
        scheduleTask.setCron(cron);
        return "ok";
    }

}

